

local generalitemlist = {
   {1,"Bomb Vk1","it's a bomb.. It Explodes","models/Combine_Helicopter/helicopter_bomb01.mdl",50},
   {2,"Bomb Vk2","it's a bomb.. It Explodes double like!","models/Combine_Helicopter/helicopter_bomb01.mdl",100},
   {3,"Bomb Vk3","it's a bomb.. It Explodes triple like!","models/Combine_Helicopter/helicopter_bomb01.mdl",300},
   {4,"Bomb Vk4","it's a bomb.. It Explodes triple like!","models/Combine_Helicopter/helicopter_bomb01.mdl",300},
   {5,"Bomb Vk5","it's a bomb.. It Explodes triple like!","models/Combine_Helicopter/helicopter_bomb01.mdl",300},
   {6,"Bomb Vk6","it's a bomb.. It Explodes triple like!","models/Combine_Helicopter/helicopter_bomb01.mdl",300},
   {7,"Bomb Vk7","it's a bomb.. It Explodes triple like!","models/Combine_Helicopter/helicopter_bomb01.mdl",300},
   {8,"Bomb Vk8","it's a bomb.. It Explodes triple like!","models/Combine_Helicopter/helicopter_bomb01.mdl",300},
   {9,"Bomb Vk9","it's a bomb.. It Explodes triple like!","models/Combine_Helicopter/helicopter_bomb01.mdl",300},
   {10,"Bomb Vk10","it's a bomb.. It Explodes triple like!","models/Combine_Helicopter/helicopter_bomb01.mdl",300},
   {11,"Bomb Vk11","it's a bomb.. It Explodes triple like!","models/Combine_Helicopter/helicopter_bomb01.mdl",300},
   {12,"Bomb Vk12","it's a bomb.. It Explodes triple like!","models/Combine_Helicopter/helicopter_bomb01.mdl",300},
   {13,"Bomb Vk13","it's a bomb.. It Explodes triple like!","models/Combine_Helicopter/helicopter_bomb01.mdl",300},
   {14,"Bomb Vk14","it's a bomb.. It Explodes triple like!","models/Combine_Helicopter/helicopter_bomb01.mdl",300},
   {15,"Bomb Vk15","it's a bomb.. It Explodes triple like!","models/Combine_Helicopter/helicopter_bomb01.mdl",300},
   {16,"Bomb Vk16","it's a bomb.. It Explodes triple like!","models/Combine_Helicopter/helicopter_bomb01.mdl",300}

}

local cart = {}
		
local TradingFrame = vgui.Create("DFrame")
      TradingFrame:SetPos(ScrW()/2,ScrH()/2)
      TradingFrame:SetSize(610,410)
      TradingFrame:SetTitle("Trading")
      TradingFrame:MakePopup()
	  
local AcceptButton = vgui.Create('DButton',TradingFrame)
	AcceptButton:SetSize(70, 25)
	AcceptButton:SetPos(420, 380)
	AcceptButton:SetText('Buy')
	AcceptButton.DoClick = function() end
	
local CancelButton = vgui.Create('DButton',TradingFrame)
	CancelButton:SetSize(70, 25)
	CancelButton:SetPos(520, 380)
	CancelButton:SetText('Cancel')
	CancelButton.DoClick = function() TradingFrame:Remove() end
	
	
local PlayerCredits = vgui.Create('DLabel',TradingFrame)
	PlayerCredits:SetPos(20, 380)
	PlayerCredits:SetText('Current Credits: '..LocalPlayer():GetNWInt("credits"))
	PlayerCredits:SizeToContents()
	PlayerCredits:SetTextColor(Color(255, 255, 255, 255))
	
local PlayerCreditsAfter = vgui.Create('DLabel',TradingFrame)
	PlayerCreditsAfter:SetPos(170, 380)
	PlayerCreditsAfter:SetText('Credits After: '..LocalPlayer():GetNWInt("credits"))
	PlayerCreditsAfter:SizeToContents()
	PlayerCreditsAfter:SetTextColor(Color(255, 255, 255, 255))

local CartItems= vgui.Create('DLabel',TradingFrame)
	CartItems:SetPos(300, 380)
	CartItems:SetText('Items In Cart: '..table.Count( cart ))
	CartItems:SizeToContents()
	CartItems:SetTextColor(Color(255, 255, 255, 255))

	
local PropertySheet = vgui.Create( "DPropertySheet", TradingFrame )
	  PropertySheet:SetPos( 5, 32 )
	  PropertySheet:SetSize( 600, 340 )
	
local Info1 = vgui.Create('DLabel',PropertySheet)
	Info1:SetPos(100, 20)
	Info1:SetText('Shopping Cart')
	Info1:SizeToContents()
	Info1:SetTextColor(Color(0,0, 255, 255))
	
local Info2 = vgui.Create('DLabel',PropertySheet)
	Info2:SetPos(400, 20)
	Info2:SetText('Trader Inventory')
	Info2:SizeToContents()
	Info2:SetTextColor(Color(0,0, 255, 255))
	
 -- help tab's
local GenTrade = vgui.Create( "DPanel", TradingFrame )
GenTrade:SetPos( 25, 50 )
GenTrade:SetSize( 250, 250 )
GenTrade.Paint = function() -- Paint function
    surface.SetDrawColor( 255, 255, 255, 255 ) -- Set our rect color below us; we do this so you can see items added to this panel
    surface.DrawRect( 0, 10, PropertySheet:GetWide()/2-20, PropertySheet:GetTall()-50 ) -- Draw the rect
	surface.SetDrawColor( 255, 255, 255, 255 ) -- Set our rect color below us; we do this so you can see items added to this panel
    surface.DrawRect( PropertySheet:GetWide()/2+10, 10, PropertySheet:GetWide()/2, PropertySheet:GetTall()-50 ) -- Draw the rect
end

	
local PremadeShips = vgui.Create( "DPanel", TradingFrame )
PremadeShips:SetPos( 25, 50 )
PremadeShips:SetSize( 250, 250 )
PremadeShips.Paint = function() -- Paint function
	surface.SetDrawColor( 255, 255, 255, 255 ) -- Set our rect color below us; we do this so you can see items added to this panel
    surface.DrawRect( 0, 10, PropertySheet:GetWide()/2-25, PropertySheet:GetTall()-50 ) -- Draw the rect
	surface.SetDrawColor( 255, 255, 255, 255 ) -- Set our rect color below us; we do this so you can see items added to this panel
    surface.DrawRect( PropertySheet:GetWide()/2+10, 10, PropertySheet:GetWide()/2, PropertySheet:GetTall()-50 ) -- Draw the rect
end

local ShipParts = vgui.Create( "DPanel", TradingFrame )
ShipParts:SetPos( 25, 50 )
ShipParts:SetSize( 250, 250 )
ShipParts.Paint = function() -- Paint function
    surface.SetDrawColor( 255, 255, 255, 255 ) -- Set our rect color below us; we do this so you can see items added to this panel
    surface.DrawRect( 0, 10, PropertySheet:GetWide()/2-25, PropertySheet:GetTall()-50 ) -- Draw the rect
	surface.SetDrawColor( 255, 255, 255, 255 ) -- Set our rect color below us; we do this so you can see items added to this panel
    surface.DrawRect( PropertySheet:GetWide()/2+10, 10, PropertySheet:GetWide()/2, PropertySheet:GetTall()-50 ) -- Draw the rect
end

local LSMod = vgui.Create( "DPanel", TradingFrame )
LSMod:SetPos( 25, 50 )
LSMod:SetSize( 250, 250 )
LSMod.Paint = function() -- Paint function
	
    surface.SetDrawColor( 255, 255, 255, 255 ) -- Set our rect color below us; we do this so you can see items added to this panel
    surface.DrawRect( 0, 10, PropertySheet:GetWide()/2-25, PropertySheet:GetTall()-50 ) -- Draw the rect
	surface.SetDrawColor( 255, 255, 255, 255 ) -- Set our rect color below us; we do this so you can see items added to this panel
    surface.DrawRect( PropertySheet:GetWide()/2+10, 10, PropertySheet:GetWide()/2, PropertySheet:GetTall()-50 ) -- Draw the rect
end







function BuyItems()  
	for k,v in pairs(cart) do 
	RunConsoleCommand("addtoinv", k, v)	
	table.Empty(cart)
	
	end 
end



function AddToCart(id,amount)
	LocalPlayer():ChatPrint("Adding "..amount.." of "..generalitemlist[id][2].." to your Shopping Cart.")
	cart[id] = (cart[id] or 0) + amount
	
	PrintTable(cart)
	UpdatePlyCart(id,amount)
	CartItems:SetText('Items In Cart: '..table.Count( cart ))
	CartItems:SizeToContents()
	
	local cost       = generalitemlist[id][5]*amount
	LocalPlayer():SetNWInt("credits",LocalPlayer():GetNWInt("credits")-cost) --this is TEMP VALUE
	PlayerCreditsAfter:SetText('Credits After: '..LocalPlayer():GetNWInt("credits")-cost)
	PlayerCreditsAfter:SizeToContents()
	

end





local credits    = LocalPlayer():GetNWInt("credits")
	

	
function UpdatePlyCart(id,amount)
	
	
	
	
	count = table.Count( cart )
	
	if count == 17 then 
	LocalPlayer():ChatPrint("Your Cart Is Full!")
	return end
	
	j = count-1
	 
	print(count)
	
	local supply     = amount
	
	local itemname   = generalitemlist[id][2]
	local info       = generalitemlist[id][3]
	local modelpath  = generalitemlist[id][4]
	local sell       = generalitemlist[id][5]
	
	
	
	local PlyItem = vgui.Create('SpawnIcon', GenTrade)

	PlyItem:SetPos(10 + (100 + ((j % 4) * 70 - 107)), 18+(math.floor(j/4)*70) )
	PlyItem:SetModel(modelpath)
	PlyItem:SetToolTip("  "..itemname..'\n Sells For: '..sell..' Credits \n Supply Left: '..supply..'\n \n '..info)
	PlyItem.OnMousePressed = function()  end
	PlyItem.OnMouseReleased = function()  end

	local PlyItemName = vgui.Create('DLabel', PlyItem)
	PlyItemName:SetPos(2, 0)
	PlyItemName:SetText(itemname)
	PlyItemName:SizeToContents()
	PlyItemName:SetTextColor(Color(0, 0, 255, 255))

	local PlyItemCost = vgui.Create('DLabel', PlyItem)
	PlyItemCost:SetPos(2, 50)
	PlyItemCost:SetText('Credits: '..sell)
	PlyItemCost:SizeToContents()
	PlyItemCost:SetTextColor(Color(0, 255, 0, 255))
end
	



function GetNPCInventory(itemnumber,itemname,info,modelpath,cost)

	for i=1,#generalitemlist do
	
	
	
	local itemnumber = generalitemlist[i][1]
	local itemname   = generalitemlist[i][2]
	local info       = generalitemlist[i][3]
	local modelpath  = generalitemlist[i][4]
	local cost       = generalitemlist[i][5]
	LocalPlayer():SetNWInt("item"..i,5)
	local supply     = LocalPlayer():GetNWInt("item"..i)

	
	local Item = vgui.Create('SpawnIcon', GenTrade)
	local j = i-1
	Item:SetPos(320 + (100 + ((j % 4) * 70 - 107)), 18+(math.floor(j/4)*70) )
	Item:SetModel(modelpath)
	Item:SetToolTip("  "..itemname..'\n Cost: '..cost..'\n Supply Left: '..supply..'\n \n '..info)	
	Item.OnMousePressed = function() 

	if LocalPlayer():GetNWInt("item"..i) > 1 then
	



local AmountTab = vgui.Create('DFrame',GenTrade)
AmountTab:SetSize(160, 115)
AmountTab:Center()
AmountTab:SetTitle('Amount To Add To Cart')
AmountTab:SetSizable(true)
AmountTab:SetDeleteOnClose(true)
AmountTab:MakePopup()

local AmountPanel = vgui.Create('DPanel',AmountTab)
AmountPanel:SetSize(140, 50)
AmountPanel:SetPos(10, 30)

local AmountSelect = vgui.Create('DNumSlider',AmountTab)
AmountSelect:SetSize(120, 40)
AmountSelect:SetPos(20, 35)
AmountSelect:SetDecimals(0)
AmountSelect:SetText('How Many? '..supply..' left.')
AmountSelect:SetMinMax( 1, supply)

AcceptButton = vgui.Create('DButton',AmountTab)
AcceptButton:SetSize(70, 25)
AcceptButton:SetPos(45, 85)
AcceptButton:SetText('Accept')

AcceptButton.DoClick = function()
	if LocalPlayer():GetNWInt("item"..i) > 0 then
	AddToCart(i,AmountSelect:GetValue()) 
	LocalPlayer():SetNWInt("item"..i,LocalPlayer():GetNWInt("item"..i)-AmountSelect:GetValue())
	timer.Simple(1,AmountSelect:SetMinMax( 1, LocalPlayer():GetNWInt("item"..i)))
	AmountTab:Remove()
	end
	end
 else
 


 end

 end
	Item.OnMouseReleased = function()  end

	local ItemName = vgui.Create('DLabel', Item)
	ItemName:SetPos(2, 0)
	ItemName:SetText(itemname)
	ItemName:SizeToContents()
	ItemName:SetTextColor(Color(0, 0, 255, 255))

	local ItemCost = vgui.Create('DLabel', Item)
	ItemCost:SetPos(2, 50)
	ItemCost:SetText('Credits: '..cost)
	ItemCost:SizeToContents()
		if tonumber(credits) >= cost then
		ItemCost:SetTextColor(Color(0, 255, 0, 255))
		else
		ItemCost:SetTextColor(Color(255, 0, 0, 255))
		end
	end
	

	vgui.Register("item_"..item[id], ITEM )

end





	
	
PropertySheet:AddSheet( "General Trading", GenTrade, "gui/silkicons/user", false, false, "General Trading Tab." )
PropertySheet:AddSheet( "Ship's", PremadeShips, "gui/silkicons/user", false, false, "Buy Already Made Ship's." )
PropertySheet:AddSheet( "Ship Parts", ShipParts, "gui/silkicons/group", false, false, "Buy Ship Parts And Addons." )
PropertySheet:AddSheet( "Life Support Modules", LSMod, "gui/silkicons/user", false, false, "Life Support Modules Buy" )

local TestTable = {
	{"sex"},
	{"wtf"},
	{"lol"},
	{"haha"}
}


function TestMe()


lawl = vgui.Create('DFrame')

TestTable[k] = vgui.Create('DFrame')

TestTable[k] = DermaListView3:AddLine(k,v.num,v.callpath)


for k,v in pairs(TestTable) do
netitems[k] = DermaListView3:AddLine(k,v.num,v.callpath) -- Add lines
netitems[k].OnRightClick = function(self)
            local dropdown = DermaMenu()
            dropdown:AddOption("Copy", function() SetClipboardText("Umsg: "..k..", Count: "..(tostring(v.num) or "")..", Path: "..(v.callpath or "") )end)
            dropdown:Open()
        end
end

end